package com.ctrip.study.algorithm.stack;

public class MyArrayStack<T> implements MyStack<T>{
	
	private Object[] array;
	private int maxSize;
	private int top;
	
	public MyArrayStack(int maxSize) {
		this.maxSize = maxSize;
		this.array = new Object[maxSize];
		this.top = -1;
	}

	@Override
	public boolean isEmpty() {
		return top == -1;
	}

	@Override
	public void clear() {
		array = null;
		top = -1;
	}

	@Override
	public boolean push(T data) {
		top += 1;
		array[top] = data;
		return true;
	}

	@Override
	public T pop() {
		T data = (T) array[top];
		top -= 1;
		return data;
	}
	
	public static void main(String[] args) {
		
	}
	

}
